package com.sky.controller.admin;

import com.sky.dto.CategoryDTO;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.entity.Category;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.CategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 *@project sky-take-out
 * @description 管理端-分类管理控制类
 * @author yunfeng
 * @date 2023/5/5 09:34:55
 * @version 1.8
 */
@Api(tags = "管理端-分类管理相关接口")
@Slf4j
@RestController
@RequestMapping("/admin/category")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;

    /**
     * @description 分页条件查询分类信息
     * @param
     * @return
     * @author yunfeng
     * @date 2023/5/5 09:51:41
     */
    @ApiOperation("条件分页查询")
    @GetMapping("/page")
    public Result findByPage(CategoryPageQueryDTO categoryPageQueryDTO){
        PageResult pageResult = categoryService.findByPage(categoryPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * @description 新增分类信息
     * @param categoryDTO
     * @return
     * @author yunfeng
     * @date 2023/5/5 10:49:01
     */
    @ApiOperation("新增分类信息")
    @PostMapping
    public Result add(@RequestBody CategoryDTO categoryDTO){
        categoryService.add(categoryDTO);
        return Result.success();
    }

    /**
     * @description 根据类型分类查询
     * @param type
     * @return
     * @author yunfeng
     * @date 2023/5/5 10:59:34
     */
    @ApiOperation("根据分类类型查询分类")
    @GetMapping("/list")
    public Result findByType(Integer type){
        List<Category> list = categoryService.findByType(type);
        return Result.success(list);
    }


    /**
     * @description 修改分类
     * @param categoryDTO
     * @return
     * @author yunfeng
     * @date 2023/5/5 11:20:12
     */
    @ApiOperation("修改分类")
    @PutMapping
    public Result modify(@RequestBody CategoryDTO categoryDTO){
        categoryService.modify(categoryDTO);
        return Result.success();
    }

    /**
     * @description 修改分类状态
     * @param status
     * @return
     * @author yunfeng
     * @date 2023/5/5 12:04:36
     */
    @ApiOperation("修改分类状态(启用或者禁用)")
    @PostMapping ("/status/{status}")
    public Result modifyStatus(@PathVariable Integer status,Long id){
        categoryService.modifyStatus(status,id);
        return Result.success();

    }


    /**
     * @description 删除分类
     * @param id
     * @return
     * @author yunfeng
     * @date 2023/5/5 12:14:38
     */
    @ApiOperation("删除分类")
    @DeleteMapping
    public Result remove(Long id){
        categoryService.remove(id);
        return Result.success();
    }

}
